package pers.cj.pdos.controller.other;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pers.cj.pdos.controller.base.BaseController;
import pers.cj.pdos.controller.entity.ResponseList;
import pers.cj.pdos.entity.Company;
import pers.cj.pdos.entity.Custom;
import pers.cj.pdos.entity.Provider;
import pers.cj.pdos.service.*;
import pers.cj.pdos.utils.Utils;
import pers.cj.pdos.vo.*;

import java.util.List;

/**
 * 初期信息
 */
@Controller
@RequestMapping("/sett")
public class InitInfoController extends BaseController {
    @Autowired
    IGoodsService goodsService;
    @Autowired
    ICustomService customService;
    @Autowired
    IProviderService providerService;
    @Autowired
    ISettAccountService settAccountService;

    @RequiresPermissions("initInfo:query")
    @RequestMapping("/initInfo")
    public String initInfo() {
        return "sett/initInfo";
    }

    @ResponseBody
    @RequiresPermissions("initInfo:query")
    @RequestMapping("/initInfo/getGoodsInitList")
    public ResponseList getGoodsInitList(String page,
                                         String limit,
                                         String search,
                                         String storeId,
                                         String houseId){
        Company company = getCompany();
        List<GoodsVo> list = goodsService.listVoForInit(company.getId(),
                Utils.genInteger(page),
                Utils.genInteger(limit),
                Utils.genLikeData(search),
                storeId,
                houseId);
        long count = goodsService.countForInit(company.getId(),
                Utils.genLikeData(search),
                storeId,
                houseId);
        return ResponseList.success(count,list);
    }

    @ResponseBody
    @RequiresPermissions("initInfo:query")
    @RequestMapping("/initInfo/getCustomInitList")
    public ResponseList getCustomInitList(String page,
                                         String limit,
                                         String search){
        Company company = getCompany();
        List<CustomVo> list = customService.listVoForInit(company.getId(),
                Utils.genInteger(page),
                Utils.genInteger(limit),
                Utils.genLikeData(search));
        long count = customService.countForInit(company.getId(),
                Utils.genLikeData(search));
        return ResponseList.success(count,list);
    }

    @ResponseBody
    @RequiresPermissions("initInfo:query")
    @RequestMapping("/initInfo/getProviderInitList")
    public ResponseList getProviderInitList(String page,
                                          String limit,
                                          String search){
        Company company = getCompany();
        List<ProviderVo> list = providerService.listVoForInit(company.getId(),
                Utils.genInteger(page),
                Utils.genInteger(limit),
                Utils.genLikeData(search));
        long count = providerService.countForInit(company.getId(),
                Utils.genLikeData(search));
        return ResponseList.success(count,list);
    }


    @ResponseBody
    @RequiresPermissions("initInfo:query")
    @RequestMapping("/initInfo/getSettAccountInitList")
    public ResponseList getSettAccountInitList(String page,
                                            String limit,
                                            String search){
        Company company = getCompany();
        List<SettAccountVo> list = settAccountService.listVoForInit(Utils.genInteger(page),
                Utils.genInteger(limit),
                company.getId(),
                Utils.genLikeData(search));
        long count = settAccountService.countForInit(company.getId(),
                Utils.genLikeData(search));
        return ResponseList.success(count,list);
    }
}
